package cn.lg.soar.message.mapper;

import cn.lg.soar.message.entity.Notice;
import cn.lg.soar.message.model.NoticeVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
public interface NoticeMapper extends BaseMapper<Notice> {

    @Select("SELECT a.*, b.`status` `readStatus` FROM lg_msg_notice a " +
            "LEFT JOIN lg_msg_notice_recipient b ON a.id=b.notice_id AND b.user_id=#{userId} " +
            "WHERE a.recipient_type=0 OR (a.recipient_type=1 AND b.id IS NOT NULL) ORDER BY datetime")
    IPage<NoticeVo> page(IPage<NoticeVo> page, @Param("userId") Long userId);

}
